<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        html,
        body {
            width: 100%;
            height: 100%;
        }
        
        .outer {
            width: 400px;
            height: 100%;
            background: blue;
            margin: 0 auto;
            display: flex;
            align-items: center;
        }
        
        .inner {
            position: relative;
            width: 100%;
            height: 0;
            /* 相对于父元素的padding-bottom  所以每次都为宽度的一半 */
            padding-bottom: 50%;
            background: red;
        }
        
        .box {
            position: absolute;
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
        }
    </style>
</head>

<body>
    <div class="outer">
        <div class="inner">
            <div class="box">hello</div>
        </div>
    </div>
</body>

</html>